package jUnitTest;

import java.io.FileInputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.junit.Test;

public class TestCollection {

	@Test
	public void test() {
		Dog[] ds = new Dog[10];
		for (int i = 0; i < ds.length; i++) {
			ds[i] = new Dog((int) (Math.random() * 10));
			System.out.print(ds[i].weight + " ");
		}
		System.out.println();
		Arrays.sort(ds);
		for (int i = 0; i < ds.length; i++) {
			System.out.print(ds[i].weight + " ");
		}
		System.out.println();

	}

	@Test
	public void testProperties() throws Exception {
		Properties properties = new Properties();
		Map<String, String> map = new HashMap<String, String>();
		properties.load(new FileInputStream("data.properties"));
		System.out.println("=============map键值对输出=============");
		for (Object o : properties.keySet()) {
			String string = o.toString();
			map.put(string, properties.getProperty(string).trim());
			System.out.println("<" + string + "," + map.get(string) + ">");
		}
		System.out.println("=============  xml 输出   =============");
		System.out.println("<User>");
		for (String s : map.keySet()) {
			String title = s + ">";
			String str = "<" + title + " " + map.get(s) + " </" + title;
			System.out.println(str);
		}
		System.out.println("</User>");
		System.out.println("============json 键值对输出============");
		StringBuilder sb = new StringBuilder();
		sb.append("{");
		for (String s : map.keySet()) {
			sb.append(s + ":" + map.get(s) + ",");
		}
		sb.setLength(sb.length() - 1);
		sb.append("}");
		System.out.println(sb.toString());
	}

	public class Dog implements Comparable<Dog> {

		int weight;

		public Dog(int weight) {
			super();
			this.weight = weight;
		}

		public int getWeight() {
			return weight;
		}

		public void setWeight(int weight) {
			this.weight = weight;
		}

		@Override
		public int compareTo(Dog o) {
			// TODO Auto-generated method stub
			return this.weight - o.weight;
		}

	}
}
